package com.iflytek.cosmo.ocr.support.license.client;

import com.iflytek.cosmo.ocr.support.license.LicenseProcessor;

/**
 * @author <a href=mailto:ktyi@iflytek.com>伊开堂</a>
 * @date 2021/2/3
 */
public abstract class AbstractClientLicenseProcessor extends LicenseProcessor {

    /**
     * 授权码子类解密
     *
     * @param license 授权码
     *
     * @return 验证结果
     */
    public abstract ClientLicense decode(String license);

    /** 解密公共部分 */
    public static ClientLicense decodeBaseInfo(String license) {
        try {
            String licenseStr = decryptLicense(license);
            return new ClientLicense(licenseStr);
        }
        catch (Exception e) {
            System.out.println("解密异常, 验证失败");
            e.printStackTrace();
        }
        return null;
    }

    protected static String decryptLicense(String license) throws Exception {
        byte[] decodedText = decrypt(base64Decode(license));
        return new String(decodedText);
    }

}
